import requests
from lxml import etree
import random

url = "https://www.meishij.net/chufang/diy/"

headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36"
}

response = requests.get(url,headers=headers)

html = etree.HTML(response.content.decode())
name = html.xpath("//strong")

url = "http://127.0.0.1:8000/foods/"
data = {"name": "姜汁松花蛋", "price": "18", "picture": "1.jpg", "description": "蛋", "type_id": "1"}

for n in name:
    food_name = n.text
    data["name"] = food_name
    data["price"] = random.randint(20,100)
    response = requests.post(url = url,data = data)
    print(response.json())